import datetime
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.select import Select
from datetime import datetime
class Base():
    def __init__(self,driver):
        self.driver=driver
    def goto(self,url):
        self.driver.get(url)
    def find_element(self,loc):
        try:
            WebDriverWait(self.driver,20,0.5).until(lambda driver:driver.find_element(*loc).is_displayed())
            return self.driver.find_element(*loc)
        except Exception as e:
            print(e)
            time = datetime.now().strftime("%Y%m%d_%H%M%S")
            self.driver.save_screenshot(f"baidu{time}.png")
    def click(self,loc):
        self.find_element(loc).click()
    def send_keys(self,loc,info):
        self.find_element(loc).send_keys(info)
    def clear(self,loc):
        self.find_element(loc).clear()
    def text(self,loc):
        return self.find_element(loc).text
    def ENTER(self,loc):
        self.find_element(loc).send_keys(Keys.ENTER)
    def qiehuan(self):
        self.driver.switch_to.window(self.driver.window_handles[-1])
    def xiala_value(self,loc,info):
        ss=Select(self.find_element(loc))
        ss.select_by_value(info)
    def gundong(self):
        self.driver.execute_script("window scrollTo(0,document.body.scrollToHeight)")
